<template>
  <!-- 创建新租表单第四步 - 确认会审单并提交 -->
  <div class="container">
    <div>
      <component :is="whichComponent"></component>
    </div>
    <div class="button-wrapper d-flex a-center j-center m-t30">
      <el-button @click="goBack">返回上一级</el-button>
      <el-button @click="onSubmit()" color="#FF7B50" style="color: #fff">提交会审单</el-button>
    </div>
  </div>
</template>

<script setup>
import {
  ElMessage,
} from "element-plus";
import { useRouter } from "vue-router";
import { contractApi as contractApi2 } from "@/api/assets";
import { ref, onMounted, shallowRef } from "vue";
import { localGet } from "@/common/utils/GlobalUtils";
import { clearCache } from "@/utils/createRoutes";

import Template1 from "../template1/step4.vue";
import TemplateWuYe from "../templateWuYe/step4.vue";
import TemplateYiZhan from "../templateYiZhan/step4.vue";
const router = useRouter();
const contractTemplateId = router.currentRoute.value.params.contractTemplateId;

let whichComponent = shallowRef(null);

const getTemplateTy = (i) => {
  //btnStatekey.value = i;
  switch (contractTemplateId) {
    case "1":
    case "2":
    case "3":
    case "4":
      whichComponent.value = Template1;
      break;
    case "5":
      whichComponent.value = TemplateWuYe;
      break;
    case "6":
      whichComponent.value = TemplateYiZhan;
      break;
    default:
      break;
  }
};

const contractId = ref("");


const emits = defineEmits(["nextStep"]);

// 返回上一级
const goBack = () => {
  emits("nextStep", "GoSupplementaryForm");
};

// 提交会审单
const onSubmit = () => {
  contractApi2
    .saveCheckupInfo({
      contractId: contractId.value, // 合同编号
    })
    .then((res) => {
      if (res.code == 200) {
        ElMessage.success("提交成功!");
        setTimeout(() => {
          router.push({ path: `/asset/collaborativeApproval` });
        }, 1000);
        clearCache({ title: '创建新租表单' });
        // router.push({ path: `/asset/collaborativeApproval/createXinZhuForm/index` });
      }
    });
};

onMounted(() => {
  getTemplateTy()
  contractId.value = localGet("contractId");
});
</script>

<style lang="scss" scoped>
.fileVoList {
  .fileItem {
    .fileItem-font {
      color: #ff7b56;
      cursor: pointer;
    }
  }
}


.container {
  width: 100%;
  height: auto !important;

  .card-box {
    width: 100%;

    .input-width {
      width: 548px;
    }

    .el-form-item-width {
      width: 100%;
    }
  }

  .button-wrapper {
    width: 100%;
  }
}
</style>
